﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace VentaPorCatalogos.Pages
{
    public class PageSearch : VentaPorCatalogos.Page
    {
        // Asignar a los controles de filtrado las cadenas recibidas en un QueryString
        // usamos la palabra "params" para indicar que podemos recibir N parametros
        protected void AsignarFiltrosQueryString(params System.Web.UI.Control[] pControlesFiltro)
        {
            string[] wFiltros;
            int wIndexFiltro = 0;

            if (string.IsNullOrEmpty(Request["Filtro"])) 
                return;

            if (Request["Filtro"].Contains("|"))
            {
                wFiltros = Request["Filtro"].Split('|');
            }
            else
            {
                wFiltros = new string[] { Request["Filtro"] };
            }
                        
            foreach (string wFiltro in wFiltros)
            {
                if (pControlesFiltro.Length < (wIndexFiltro + 1))
                    break;

                System.Web.UI.Control oControl = pControlesFiltro[wIndexFiltro];
                if (oControl is System.Web.UI.WebControls.TextBox)
                {
                    (oControl as System.Web.UI.WebControls.TextBox).Text = wFiltros[wIndexFiltro];
                }
                else
                    if (oControl is System.Web.UI.WebControls.DropDownList)
                    {
                        (oControl as System.Web.UI.WebControls.DropDownList).SelectedValue = wFiltros[wIndexFiltro];
                    }
                wIndexFiltro++;
            }
        }
    }
}